import sys,os
from subprocess import *

if len(sys.argv)<2:
    print 'python getMeanSize.py lstFile'
    exit(1)

class File:
    cnt=0
    entries=0
    size=0
    def __init__(self, cnt, entries, size):
    	self.cnt=cnt
    	self.entries=entries
    	self.size=size

fi=open(sys.argv[1],'r')
prefix=sys.argv[1].split('.')[0]
type=prefix
mapT={}
allT=[]
type_cnt=0
ind=0
for line in fi:
    line=line.strip()
    if len(line)<1:
    	continue
    temp=line.split('\t')
    if len(temp)>1:
    	type=temp[1]
    if type not in mapT:
    	mapT[type]=type_cnt
    	allT.append(File(0,0,0))
    	type_cnt+=1
    ind=mapT[type]
    allT[ind].cnt+=1
    cmd=['wc','-l',prefix+'/'+temp[0]+'.'+prefix]
    p=Popen(cmd,stdout=PIPE)
    allT[ind].entries+=int(p.stdout.readline().split()[0])
    cmd=['du','-b',prefix+'/'+temp[0]+'.'+prefix]
    p=Popen(cmd,stdout=PIPE)
    allT[ind].size+=int(p.stdout.readline().split()[0])
    #cmd='wc -l '+prefix+'/'+temp[0]+'.'+prefix+' >temp'
    #os.system(cmd)
    #num=int(open('temp').readline().split()[0])
    #allT[ind].entries+=num
    #cmd='du -b '+prefix+'/'+temp[0]+'.'+prefix+' >temp'
    #os.system(cmd)
    #allT[ind].size+=int(open('temp').readline().split()[0])
    #if type_cnt%10==0:
    #	print type_cnt
fi.close()
for x in mapT:
    ind=mapT[x]
    print x+'\t'+str(allT[ind].cnt)+'\t'+str(1.0*allT[ind].entries/allT[ind].cnt)+'\t'+str(1.0*allT[ind].size/allT[ind].cnt)

